package com.streetlight.lampcursor.ui.status

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.streetlight.lampcursor.model.StreetLightData
import com.streetlight.lampcursor.repository.StreetLightRepository
import kotlinx.coroutines.launch

class StatusViewModel : ViewModel() {

    private val repository = StreetLightRepository()

    private val _streetLightData = MutableLiveData<StreetLightData>()
    val streetLightData: LiveData<StreetLightData> = _streetLightData

    private val _isOnline = MutableLiveData<Boolean>(false)
    val isOnline: LiveData<Boolean> = _isOnline

    fun loadStatusData() {
        viewModelScope.launch {
            try {
                val data = repository.getStreetLightData()
                _streetLightData.value = data
                _isOnline.value = data.isOnline
            } catch (e: Exception) {
                // 处理错误
            }
        }
    }
} 